const StudentModel = require('../models/StudentModel')

const StudentService = {
  add: async ({ username, major, classes, year }) => {
    return StudentModel.create({
      username,
      major,
      classes,
      year
    })
  },

  getList: async ({ username }) => {
    if (username) {
      return StudentModel.find({ username })
    } else {
      return StudentModel.find()
    }
  },

  delList: async ({ username }) => {
    return StudentModel.deleteOne({ username })
  },

  putList: async ({ username, major, classes, year }) => {
    return StudentModel.updateOne({ username }, { major, classes, year })
  },

  getScoreList: async ({ major }) => {
    return StudentModel.find({ major })
  }
}

module.exports = StudentService
